package org.cjstudio.holypoopsgrs.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.cjstudio.holypoopsgrs_interface.game.security.HolyPoopsSecurityUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Path("secret")
@Component("secretResource")
@Scope("singleton")
public class SecretResourceImpl {

	@GET
	@Path("{key}/{encoded}")
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	public String getMessage(
			@PathParam("key") String key, 
			@PathParam("encoded") String encoded) {

		System.out.println("SecretResource: secret/" + key + "/" + encoded);
		System.out.println("Key : " + key);
		System.out.println("Encoded : " + encoded);

		/*
		if(절대뚫리지않는굉장히복잡한알고리즘.굉장히복잡한키값인증(key) == false) {
			return null;
		}
		*/
		
		String decoded = null;
		try {
			decoded = HolyPoopsSecurityUtils.decrypt(encoded, key);
			System.out.println("Decoded : " + decoded);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return decoded;
	}
}
